//
//  UIView+ZRRequestHint.m
//  Mcilife
//
//  Created by 黄涛 on 2019/4/18.
//  Copyright © 2019 syhzg. All rights reserved.
//

#import "UIView+ZRRequestHint.h"
#import <objc/runtime.h>

// 定义关联的key
static const char * id_hintView = "ZRRequestHintKey";

@implementation UIView (ZRRequestHint)

- (void)zr_show:(void (^)(ZRRequestHint * _Nonnull))block{ZRWeakSelf
    
    [self.superview layoutIfNeeded];
    ZRRequestHint * hintView = [[ZRRequestHint alloc] initWithView:self];
  
    hintView.transform = CGAffineTransformMakeScale(0.1, 0.1);
    hintView.alpha = 0;

    [UIView animateWithDuration:0.25 animations:^{
        hintView.alpha = 1;
        hintView.transform = CGAffineTransformIdentity;
    }];
    
 
    weakSelf.hintView = hintView;
    
    block(hintView);
}

- (void)zr_hide{
    
    [UIView animateWithDuration:0.25 animations:^{
       self.hintView.transform = CGAffineTransformMakeScale(0.1, 0.1);
       self.hintView.alpha = 0;
    } completion:^(BOOL finished) {

       [self.hintView removeFromSuperview];
    }];
   
}


- (ZRRequestHint *)hintView{
    return objc_getAssociatedObject(self, id_hintView);
}

- (void)setHintView:(ZRRequestHint *)hintView{
    return objc_setAssociatedObject(self, id_hintView, hintView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}


@end
